<template>
  <header>
    <el-avatar size="40" :src="userDetail.avator || userAvator" />
    <span style="margin-left: 10px">{{ userDetail.name || 'CRM 客服' }}</span>
    <el-popover placement="right" trigger="click" v-model:visible="visible">
      <template #reference>
        <div class="customer-status">
          <div class="online" v-if="CustomerStatus">
            <div class="dot"></div>
            <div>在线</div>
          </div>
          <div class="offline" v-else>
            <div class="dot"></div>
            <div>离线</div>
          </div>
        </div>
      </template>
      <template #default>
        <div class="demo-rich-conent" style="display: flex; flex-direction: column">
          <div class="change-status" @click="setMerStatus(true)">
            <div style="width: 12px">
              <el-icon size="12" v-if="CustomerStatus"><Check /></el-icon>
            </div>
            <div class="dot"></div>
            在线
          </div>
          <div class="change-status" @click="setMerStatus(false)">
            <div style="width: 12px">
              <el-icon size="12" v-if="!CustomerStatus"><Check /></el-icon>
            </div>
            <div class="dot-not"></div>
            离线
          </div>
        </div>
      </template>
    </el-popover>
  </header>
</template>

<script lang="ts" setup>
import { Check } from '@element-plus/icons-vue'

const CustomerStatus = ref(true)
const visible = ref(false)
const userAvator = ref(
  ''
)
const props = defineProps({
  userDetail: Object
})
const emit = defineEmits(['setWebSocketStatus'])
const setMerStatus = (val) => {
  visible.value = false
  CustomerStatus.value = val
  emit('setWebSocketStatus', val)
}
// 关闭状态
const echoStatus = () => {
  CustomerStatus.value = false
}
defineExpose({ echoStatus })
</script>

<style lang="scss" scoped>
header {
  padding: 13px 12px;
  background-color: #007aff;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  span {
    color: #fff;
    font-size: 16px;
  }
  .customer-status {
    margin-left: 5px;
    width: 53px;
    height: 18px;
    border-radius: 9px;
    margin-top: 5px;
    .online {
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 12px;
      color: rgba(0, 0, 0, 0.65);
      background: #eaffeb;
      border-radius: 9px;
      cursor: pointer;
      .dot {
        width: 6px;
        height: 6px;
        margin-right: 3px;
        border-radius: 50%;
        background: #48d452;
      }
    }
    .offline {
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 12px;
      color: rgba(0, 0, 0, 0.65);
      background: #f3f3f3;
      border-radius: 9px;
      cursor: pointer;
      .dot {
        width: 6px;
        height: 6px;
        margin-right: 3px;
        border-radius: 50%;
        background: #999;
      }
    }
  }
}
.change-status {
  display: flex;
  align-items: center;
  padding: 7px;
  cursor: pointer;
  .dot {
    width: 10px;
    height: 10px;
    margin: 0 8px;
    border-radius: 50%;
    background: #48d452;
  }
  .dot-not {
    width: 10px;
    height: 10px;
    margin: 0 8px;
    border-radius: 50%;
    background: #999;
  }
  .dot-logout {
    width: 10px;
    height: 10px;
    margin: 0 8px;
    border-radius: 50%;
    background: #ff6700;
  }
}
</style>
